package com.robotserver.orders.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.jd.open.api.sdk.DefaultJdClient;
import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.JdException;
import com.robotserver.orders.common.DateFormatUtil;
import com.robotserver.orders.common.DateUtil;
import com.robotserver.orders.common.Math;
import com.robotserver.orders.common.Md5Util;
import com.robotserver.orders.entity.JdOrders;
import com.robotserver.orders.mapper.JdOrdersMapper;
import com.robotserver.orders.mapper.SysSettingMapper;
import com.robotserver.orders.service.JdCpsOrderService;
import com.robotserver.orders.vo.JdOrderTimeVO;
import com.robotserver.orders.vo.jdcpsorder.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @Auther: jianghan
 * @Date: 2020/8/20 16:00
 * @Description:
 */
@Service
public class JdCpsOrderServiceImpl implements JdCpsOrderService {

    private static Logger logger = LoggerFactory.getLogger(JdCpsOrderServiceImpl.class);

    private static int pageSize = 20;
    private static int type = 3;
    @Value("${jd.cps.order.url}")
    private String orderListUrl;
    @Autowired
    private JdOrdersMapper jdOrdersMapper;
    @Value("${jd.sdk.url}")
    private String jdSdkUrl;
    @Autowired
    private SysSettingMapper sysSettingMapper;

    @Autowired
    private RestTemplate restTemplate;
    @Override
    public JdCpsOrderResp getCpsOrders(String code, JdOrderTimeVO jdOrderTimeVO, int pageIndex, Integer currType) {
        //String begin = DateFormatUtil.format(DateFormatUtil.StringToDate(times),"yyyy-MM-dd HH:mm:ss");
        //String end = DateFormatUtil.format(new Date(DateFormatUtil.StringToDate(times).getTime()+60000l),"yyyy-MM-dd HH:mm:ss");

//        JSONObject param = new JSONObject();
//
//        param.put("code",code);
//        param.put("startTime",jdOrderTimeVO.getBeginTime());
//        param.put("endTime",jdOrderTimeVO.getEndTime());
//        param.put("itemsPerPage",pageSize+"");
//        param.put("curPage",pageIndex+"");
//
//        if (currType!=null){
//            type = currType;
//        }
//
//        param.put("type",type+"");
//
//
//        HttpHeaders headers = new HttpHeaders();
//        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
//        headers.setContentType(type);
//        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
//        HttpEntity<String> formEntity = new HttpEntity<>(param.toString(), headers);
//
//        ResponseEntity<JdCpsOrderResp> response = restTemplate.postForEntity(orderListUrl, formEntity, JdCpsOrderResp.class);
//        JdCpsOrderResp jdCpsOrderResp = response.getBody();
//        return jdCpsOrderResp;



        String sign = "";
        String jy_sdk_url = "https://jyapi.jd.com/open-api/jy/order/query-items";
        String appKey = "f5ca2c063d6747d696524de8f206035f";
        String secretKey = "392fa7a93f802423d2adb1566d9866ac";
        //String code = appKey;
        JSONObject param = new JSONObject();

        if (currType!=null){
            type = currType;
        }

        param.put("code",appKey);
        param.put("startTime",jdOrderTimeVO.getBeginTime());
        param.put("endTime",jdOrderTimeVO.getEndTime());
        param.put("pageSize",pageSize+"");
        param.put("pageNo",pageIndex+"");
        param.put("type",type);

        String body = param.toString();
        long current = System.currentTimeMillis();
        String signBody = appKey + secretKey + current + body;
        sign = Md5Util.getMd5(signBody);
        String url = jy_sdk_url + "?appKey=" + appKey
                + "&sign=" + sign + "&current=" + current;

        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        HttpEntity<String> formEntity = new HttpEntity<>(body, headers);

        ResponseEntity<JdCpsOrderResp> response = restTemplate.postForEntity(url, formEntity, JdCpsOrderResp.class);
        JdCpsOrderResp jdCpsOrderResp = response.getBody();
        return jdCpsOrderResp;


    }

    @Override
    public void orderAdd(JdCpsOrderData orders) {
        int now = DateUtil.getNowTime();
        if (orders==null || orders.getOrderRespList()==null || orders.getOrderRespList().size()==0){
            logger.info("cps jd order is null.");
            return ;
        }
        List<JdCpsOrderInfo> orderInfoList = orders.getOrderRespList();
        for (JdCpsOrderInfo order:orderInfoList){
            List<JdCpsSkuInfo> skuInfos = order.getSkuInfoList();
            for (JdCpsSkuInfo skuInfo:skuInfos){
                int bizStatus = bizStatus(skuInfo.getValidCode());
                if (bizStatus==4){
                    // 无效订单不处理
                    continue;
                }
                if (skuInfo.getPrice()==null || skuInfo.getPrice().doubleValue()==0 ){
                    continue;
                }
                // 根据订单号，商品id查询订单是否存在
                JdOrders jdOrders = jdOrdersMapper.getBySkuIdAndOrderId(skuInfo.getSkuId(),order.getOrderId());
                if (jdOrders!=null){
                    if(skuInfo.getSkuReturnNum()!=null && skuInfo.getSkuReturnNum().intValue()>0){
                        bizStatus = 2;      // 订单失效
                    }
                    // 修改
                    if (skuInfo.getValidCode().intValue()!=jdOrders.getSkuValidCode().intValue()
                            || ((jdOrders.getPrice()==null || jdOrders.getPrice()==0) && skuInfo.getPrice().doubleValue()>0)
                            || (jdOrders.getBizStatus()!=null && bizStatus!=jdOrders.getBizStatus().intValue())){      // 状态不同就修改
                        jdOrders.setUpdateTime(now);
                        jdOrders.setActualCosPrice(Math.currencyFormatToF(skuInfo.getActualCosPrice().doubleValue()));
                        jdOrders.setActualFee(Math.currencyFormatToF(skuInfo.getActualFee().doubleValue()));
                        jdOrders.setCid1(skuInfo.getFirstLevel());
                        jdOrders.setCid2(skuInfo.getSecondLevel());
                        jdOrders.setCid3(skuInfo.getThirdLevel());
                        jdOrders.setBizStatus(bizStatus);

                        jdOrders.setCommissionRate(skuInfo.getCommissionRate().doubleValue());
                        jdOrders.setCpActId(skuInfo.getCpActId());
                        jdOrders.setEstimateCosPrice(Math.currencyFormatToF(skuInfo.getEstimateCosPrice().doubleValue()));
                        jdOrders.setEstimateFee(Math.currencyFormatToF(skuInfo.getEstimateFee().doubleValue()));
                        jdOrders.setExt1(null);
                        jdOrders.setFinalRate(skuInfo.getFinalRate().doubleValue());
                        if (order.getFinishTime()!=null){
                            jdOrders.setFinishTime((int)(order.getFinishTime()/1000));
                        }else{
                            jdOrders.setFinishTime(0);
                        }
                        jdOrders.setFrozenSkuNum((int)skuInfo.getFrozenSkuNum().longValue());
                        jdOrders.setGiftCouponKey(skuInfo.getGiftCouponKey());
                        jdOrders.setGiftCouponOcsAmount(Math.currencyFormatToF(skuInfo.getGiftCouponOcsAmount().doubleValue()));
                        jdOrders.setOrderEmt(skuInfo.getOrderEmt());
                        if (order.getOrderTime()!=null){
                            jdOrders.setOrderTime((int)(order.getOrderTime()/1000));
                        }else{
                            jdOrders.setOrderTime(0);
                        }
                        jdOrders.setParentId(order.getParentId());
                        jdOrders.setPayMonth(order.getPayMonth()+"");
                        jdOrders.setPid(skuInfo.getPid());
                        jdOrders.setPlus(order.getPlus());
                        jdOrders.setPopId(order.getPopId());
                        jdOrders.setPositionId(0l);  // 没有推广位
                        jdOrders.setPrice(Math.currencyFormatToF(skuInfo.getPrice().doubleValue()));

                        jdOrders.setSiteId(skuInfo.getSiteId());
                        jdOrders.setSkuExt1(null);
                        jdOrders.setSkuName(skuInfo.getSkuName());
                        jdOrders.setSkuPayMonth(null);
                        jdOrders.setSkuPopId(skuInfo.getPopId());
                        jdOrders.setSkuValidCode(skuInfo.getValidCode());
                        jdOrders.setSubSideRate(skuInfo.getSubSideRate().doubleValue());
                        jdOrders.setSubsidyRate(skuInfo.getSubsidyRate().doubleValue());
                        jdOrders.setSubUnionId(skuInfo.getSubUnionId());
                        jdOrders.setSkuNum(skuInfo.getSkuNum().intValue());
                        jdOrders.setSkuReturnNum(skuInfo.getSkuReturnNum().intValue());

                        jdOrders.setTraceType(skuInfo.getTraceType());
                        jdOrders.setUnionAlias(skuInfo.getUnionAlias());
                        jdOrders.setUnionId(order.getUnionId());
                        jdOrders.setUnionRole(skuInfo.getUnionRole());
                        jdOrders.setUnionTag(skuInfo.getUnionTag());
                        jdOrders.setUnionTrafficGroup(skuInfo.getUnionTrafficGroup());

                        jdOrders.setValidCode(order.getValidCode());
                        jdOrdersMapper.update(jdOrders);
                    }
                }else {
                    if (bizStatus==5){   // 无效-拆单 不处理
                        continue;
                    }
                    // 添加
                    // 查询商品接口
                    String imgurl = "";
                    JdOrders newJdOrder = new JdOrders();
                    newJdOrder.setImgUrl(imgurl);
                    newJdOrder.setId(IdWorker.getId());
                    newJdOrder.setCreateTime(now);
                    newJdOrder.setUpdateTime(now);
                    newJdOrder.setBizStatus(bizStatus);

                    if(skuInfo.getSkuReturnNum()!=null && skuInfo.getSkuReturnNum().intValue()>0){
                        newJdOrder.setBizStatus(2);       // 订单失效
                    }


                    newJdOrder.setActualCosPrice(Math.currencyFormatToF(skuInfo.getActualCosPrice().doubleValue()));
                    newJdOrder.setActualFee(Math.currencyFormatToF(skuInfo.getActualFee().doubleValue()));
                    newJdOrder.setCid1(skuInfo.getFirstLevel());
                    newJdOrder.setCid2(skuInfo.getSecondLevel());
                    newJdOrder.setCid3(skuInfo.getThirdLevel());
                    newJdOrder.setCommissionRate(skuInfo.getCommissionRate().doubleValue());
                    newJdOrder.setCpActId(skuInfo.getCpActId());
                    newJdOrder.setEstimateCosPrice(Math.currencyFormatToF(skuInfo.getEstimateCosPrice().doubleValue()));
                    newJdOrder.setEstimateFee(Math.currencyFormatToF(skuInfo.getEstimateFee().doubleValue()));
                    newJdOrder.setExt1("");
                    newJdOrder.setFinalRate(skuInfo.getFinalRate().doubleValue());

                    if (order.getFinishTime()!=null){
                        newJdOrder.setFinishTime((int)(order.getFinishTime()/1000));
                    }else{
                        newJdOrder.setFinishTime(0);
                    }

                    newJdOrder.setFrozenSkuNum((int)skuInfo.getFrozenSkuNum().longValue());
                    newJdOrder.setGiftCouponKey(skuInfo.getGiftCouponKey());
                    newJdOrder.setGiftCouponOcsAmount(Math.currencyFormatToF(skuInfo.getGiftCouponOcsAmount().doubleValue()));
                    newJdOrder.setOrderEmt(skuInfo.getOrderEmt());
                    newJdOrder.setOrderId(order.getOrderId());
                    if (order.getOrderTime()!=null){
                        newJdOrder.setOrderTime((int)(order.getOrderTime()/1000));
                    }else{
                        newJdOrder.setOrderTime(0);
                    }
                    newJdOrder.setParentId(order.getParentId());
                    newJdOrder.setPayMonth(order.getPayMonth()+"");
                    newJdOrder.setPid(skuInfo.getPid());
                    newJdOrder.setPlus(order.getPlus());
                    newJdOrder.setPopId(order.getPopId());
                    newJdOrder.setPositionId(0l);
                    newJdOrder.setPrice(Math.currencyFormatToF(skuInfo.getPrice().doubleValue()));

                    newJdOrder.setSiteId(skuInfo.getSiteId());
                    newJdOrder.setSkuExt1(null);
                    newJdOrder.setSkuId(skuInfo.getSkuId());
                    newJdOrder.setSkuName(skuInfo.getSkuName());
                    newJdOrder.setSkuPayMonth(null);
                    newJdOrder.setSkuPopId(skuInfo.getPopId());
                    newJdOrder.setSkuValidCode(skuInfo.getValidCode());
                    newJdOrder.setSubSideRate(skuInfo.getSubSideRate().doubleValue());
                    newJdOrder.setSubsidyRate(skuInfo.getSubsidyRate().doubleValue());
                    newJdOrder.setSubUnionId(skuInfo.getSubUnionId());
                    newJdOrder.setSkuNum(skuInfo.getSkuNum().intValue());
                    newJdOrder.setSkuReturnNum(skuInfo.getSkuReturnNum().intValue());

                    newJdOrder.setTraceType(skuInfo.getTraceType());
                    newJdOrder.setUnionAlias(skuInfo.getUnionAlias());
                    newJdOrder.setUnionId(order.getUnionId());
                    newJdOrder.setUnionRole(skuInfo.getUnionRole());
                    newJdOrder.setUnionTag(skuInfo.getUnionTag());
                    newJdOrder.setUnionTrafficGroup(skuInfo.getUnionTrafficGroup());

                    newJdOrder.setValidCode(order.getValidCode());
                    jdOrdersMapper.add(newJdOrder);
                }
            }
        }
    }

    private int bizStatus(int validCode){
        // 16 付款 17 已完成 3 13 失效 2 无效-拆单
        switch (validCode){
            case 16:
                return 0;
            case 17:
                return 1;
            case 3:
                return 2;
            case 13:
                return 2;
            case 2:
                return 5;
        }
        return 4;
    }

    @Override
    public JdCpsOrderResp getCpsOrders_byAppKey(JdOrderTimeVO jdOrderTimeVO, int pageIndex) {
        //String begin = DateFormatUtil.format(DateFormatUtil.StringToDate(times),"yyyy-MM-dd HH:mm:ss");
        //String end = DateFormatUtil.format(new Date(DateFormatUtil.StringToDate(times).getTime()+60000l),"yyyy-MM-dd HH:mm:ss");
        String sign = "";
        String jy_sdk_url = "https://jyapi.jd.com/open-api/jy/order/query-items";
        String appKey = "f5ca2c063d6747d696524de8f206035f";
        String secretKey = "392fa7a93f802423d2adb1566d9866ac";
        String code = appKey;
        JSONObject param = new JSONObject();

        param.put("code",code);
        param.put("startTime",jdOrderTimeVO.getBeginTime());
        param.put("endTime",jdOrderTimeVO.getEndTime());
        param.put("pageSize",pageSize+"");
        param.put("pageNo",pageIndex+"");
        param.put("type",type);

        String body = param.toString();
        long current = System.currentTimeMillis();
        String signBody = appKey + secretKey + current + body;
        sign = Md5Util.getMd5(signBody);
        String url = jy_sdk_url + "?appKey=" + appKey
                + "&sign=" + sign + "&current=" + current;

        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        HttpEntity<String> formEntity = new HttpEntity<>(body, headers);

        ResponseEntity<JdCpsOrderResp> response = restTemplate.postForEntity(url, formEntity, JdCpsOrderResp.class);
        JdCpsOrderResp jdCpsOrderResp = response.getBody();
        return jdCpsOrderResp;
    }

    @Override
    public void orderAdd_byAppKey(JdCpsOrderData orders) {
        int now = DateUtil.getNowTime();
        if (orders==null || orders.getResult()==null || orders.getResult().size()==0){
            //logger.info("cps jd order is null.");
            return ;
        }
        List<JdCpsOrderInfo_new> orderInfoList = orders.getResult();
        for (JdCpsOrderInfo_new skuInfo : orderInfoList){

            logger.info("----JY order :skuid: {},orderid: {}",new Object[]{skuInfo.getSkuId(),skuInfo.getOrderId()});

            if(skuInfo.getPrice() == null || skuInfo.getPrice().doubleValue() <= 0){
                //价格等于0，不处理
                continue;
            }

            int bizStatus = bizStatus(skuInfo.getValidCode());
            if (bizStatus==4){
                // 无效订单不处理
                // continue;
            }
            if (skuInfo.getPrice()==null || skuInfo.getPrice().doubleValue()==0 ){
                // continue;
            }
            // 根据订单号，商品id查询订单是否存在
            JdOrders jdOrders = jdOrdersMapper.getBySkuIdAndOrderId(skuInfo.getSkuId(),skuInfo.getOrderId());
            if (jdOrders!=null){
                if(skuInfo.getSkuReturnNum()!=null && skuInfo.getSkuReturnNum().intValue()>0){
                    bizStatus = 2;      // 订单失效
                }
                // 修改
                if (skuInfo.getValidCode().intValue()!=jdOrders.getSkuValidCode().intValue()
                        || ((jdOrders.getPrice()==null || jdOrders.getPrice()==0) && skuInfo.getPrice().doubleValue()>0)
                        || (jdOrders.getBizStatus()!=null && bizStatus!=jdOrders.getBizStatus().intValue())){      // 状态不同就修改
                    jdOrders.setUpdateTime(now);
                    jdOrders.setActualCosPrice(Math.currencyFormatToF(skuInfo.getActualCosPrice().doubleValue()));
                    jdOrders.setActualFee(Math.currencyFormatToF(skuInfo.getActualFee().doubleValue()));
                    jdOrders.setCid1(skuInfo.getFirstLevel());
                    jdOrders.setCid2(skuInfo.getSecondLevel());
                    jdOrders.setCid3(skuInfo.getThirdLevel());
                    jdOrders.setBizStatus(bizStatus);

                    jdOrders.setCommissionRate(skuInfo.getCommissionRate().doubleValue());
                    jdOrders.setCpActId(skuInfo.getCpActId());
                    jdOrders.setEstimateCosPrice(Math.currencyFormatToF(skuInfo.getEstimateCosPrice().doubleValue()));
                    jdOrders.setEstimateFee(Math.currencyFormatToF(skuInfo.getEstimateFee().doubleValue()));
                    jdOrders.setExt1(null);
                    jdOrders.setFinalRate(skuInfo.getFinalRate().doubleValue());
                    if (skuInfo.getFinishTime()!=null){
                        jdOrders.setFinishTime((int)(skuInfo.getFinishTime()/1000));
                    }else{
                        jdOrders.setFinishTime(0);
                    }
                    jdOrders.setFrozenSkuNum((int)skuInfo.getFrozenSkuNum().longValue());
                    //jdOrders.setGiftCouponKey(skuInfo.getGiftCouponKey());
                    //jdOrders.setGiftCouponOcsAmount(Math.currencyFormatToF(skuInfo.getGiftCouponOcsAmount().doubleValue()));
                    //jdOrders.setOrderEmt(skuInfo.getOrderEmt());
                    if (skuInfo.getOrderTime()!=null){
                        jdOrders.setOrderTime((int)(skuInfo.getOrderTime()/1000));
                    }else{
                        jdOrders.setOrderTime(0);
                    }
                    jdOrders.setParentId(skuInfo.getParentId());
                    jdOrders.setPayMonth(skuInfo.getPayMonth()+"");
                    jdOrders.setPid(skuInfo.getPid());
                    //jdOrders.setPlus(skuInfo.getPlus());
                    //jdOrders.setPopId(skuInfo.getPopId());
                    jdOrders.setPositionId(0l);  // 没有推广位
                    jdOrders.setPrice(Math.currencyFormatToF(skuInfo.getPrice().doubleValue()));

                    jdOrders.setSiteId(skuInfo.getSiteId());
                    jdOrders.setSkuExt1(null);
                    jdOrders.setSkuName(skuInfo.getSkuName());
                    jdOrders.setSkuPayMonth(null);
                    //jdOrders.setSkuPopId(skuInfo.getPopId());
                    jdOrders.setSkuValidCode(skuInfo.getValidCode());
                    jdOrders.setSubSideRate(skuInfo.getSubSideRate().doubleValue());
                    jdOrders.setSubsidyRate(skuInfo.getSubsidyRate().doubleValue());
                    jdOrders.setSubUnionId(skuInfo.getSubUnionId());
                    jdOrders.setSkuNum(skuInfo.getSkuNum().intValue());
                    jdOrders.setSkuReturnNum(skuInfo.getSkuReturnNum().intValue());

                    jdOrders.setTraceType(skuInfo.getTraceType());
                    jdOrders.setUnionAlias(skuInfo.getUnionAlias());
                    //jdOrders.setUnionId(order.getUnionId());
                    jdOrders.setUnionRole(skuInfo.getUnionRole());
                    jdOrders.setUnionTag(skuInfo.getUnionTag());
                    jdOrders.setUnionTrafficGroup(skuInfo.getUnionTrafficGroup());

                    jdOrders.setValidCode(skuInfo.getValidCode());
                    jdOrdersMapper.update(jdOrders);
                }
            }else {

                if(skuInfo.getSkuReturnNum()!=null && skuInfo.getSkuReturnNum().intValue()>0){
                    bizStatus = 2;      // 订单失效
                }

                if (bizStatus==5){   // 无效-拆单 不处理
                   // continue;
                }

                // 添加
                // 查询商品接口
                String imgurl = "";
                JdOrders newJdOrder = new JdOrders();
                newJdOrder.setImgUrl(imgurl);
                newJdOrder.setId(IdWorker.getId());
                newJdOrder.setCreateTime(now);
                newJdOrder.setUpdateTime(now);
                newJdOrder.setBizStatus(bizStatus);

                if(skuInfo.getSkuReturnNum()!=null && skuInfo.getSkuReturnNum().intValue()>0){
                    newJdOrder.setBizStatus(2);       // 订单失效
                }


                newJdOrder.setActualCosPrice(Math.currencyFormatToF(skuInfo.getActualCosPrice().doubleValue()));
                newJdOrder.setActualFee(Math.currencyFormatToF(skuInfo.getActualFee().doubleValue()));
                newJdOrder.setCid1(skuInfo.getFirstLevel());
                newJdOrder.setCid2(skuInfo.getSecondLevel());
                newJdOrder.setCid3(skuInfo.getThirdLevel());
                newJdOrder.setCommissionRate(skuInfo.getCommissionRate().doubleValue());
                newJdOrder.setCpActId(skuInfo.getCpActId());
                newJdOrder.setEstimateCosPrice(Math.currencyFormatToF(skuInfo.getEstimateCosPrice().doubleValue()));
                newJdOrder.setEstimateFee(Math.currencyFormatToF(skuInfo.getEstimateFee().doubleValue()));
                newJdOrder.setExt1("");
                newJdOrder.setFinalRate(skuInfo.getFinalRate().doubleValue());

                if (skuInfo.getFinishTime()!=null){
                    newJdOrder.setFinishTime((int)(skuInfo.getFinishTime()/1000));
                }else{
                    newJdOrder.setFinishTime(0);
                }

                newJdOrder.setFrozenSkuNum((int)skuInfo.getFrozenSkuNum().longValue());
                //newJdOrder.setGiftCouponKey(skuInfo.getGiftCouponKey());
                //newJdOrder.setGiftCouponOcsAmount(Math.currencyFormatToF(skuInfo.getGiftCouponOcsAmount().doubleValue()));
                //newJdOrder.setOrderEmt(skuInfo.getOrderEmt());
                newJdOrder.setOrderId(skuInfo.getOrderId());
                if (skuInfo.getOrderTime()!=null){
                    newJdOrder.setOrderTime((int)(skuInfo.getOrderTime()/1000));
                }else{
                    newJdOrder.setOrderTime(0);
                }
                newJdOrder.setParentId(skuInfo.getParentId());
                newJdOrder.setPayMonth(skuInfo.getPayMonth()+"");
                newJdOrder.setPid(skuInfo.getPid());
                //newJdOrder.setPlus(skuInfo.getPlus());
                //newJdOrder.setPopId(skuInfo.getPopId());
                newJdOrder.setPositionId(0l);
                newJdOrder.setPrice(Math.currencyFormatToF(skuInfo.getPrice().doubleValue()));
                newJdOrder.setSiteId(skuInfo.getSiteId());
                newJdOrder.setSkuExt1(null);
                newJdOrder.setSkuId(skuInfo.getSkuId());
                newJdOrder.setSkuName(skuInfo.getSkuName());
                newJdOrder.setSkuPayMonth(null);
                //newJdOrder.setSkuPopId(skuInfo.getPopId());
                newJdOrder.setSkuValidCode(skuInfo.getValidCode());
                newJdOrder.setSubSideRate(skuInfo.getSubSideRate().doubleValue());
                newJdOrder.setSubsidyRate(skuInfo.getSubsidyRate().doubleValue());
                newJdOrder.setSubUnionId(skuInfo.getSubUnionId());
                newJdOrder.setSkuNum(skuInfo.getSkuNum().intValue());
                newJdOrder.setSkuReturnNum(skuInfo.getSkuReturnNum().intValue());

                newJdOrder.setTraceType(skuInfo.getTraceType());
                newJdOrder.setUnionAlias(skuInfo.getUnionAlias());
                //newJdOrder.setUnionId(skuInfo.getUnionId());
                newJdOrder.setUnionRole(skuInfo.getUnionRole());
                newJdOrder.setUnionTag(skuInfo.getUnionTag());
                newJdOrder.setUnionTrafficGroup(skuInfo.getUnionTrafficGroup());

                newJdOrder.setValidCode(skuInfo.getValidCode());
                jdOrdersMapper.add(newJdOrder);
            }
        }
    }

}
